﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.IO;

namespace DemoASPWC.controller
{
    /// <summary>
    /// Summary description for WebcamController
    /// </summary>
    public class WebcamController : IHttpHandler
    {

        HttpRequest request = null;
        HttpResponse response = null;
        HttpContext currContext = null;

        public void ProcessRequest(HttpContext context)
        {
            request = context.Request;
            response = context.Response;
            currContext = context;
            Capture();
            
        }

        public void Capture()
        {
            var stream = request.InputStream;
            string dump;

            using (var reader = new StreamReader(stream))
                dump = reader.ReadToEnd();

            byte[] imgByte = String_To_Bytes2(dump);
            for (int i = 0; i < imgByte.Length; i++)
            {
                
            }
        }

        private byte[] String_To_Bytes2(string strInput)
        {
            int numBytes = (strInput.Length) / 2;
            byte[] bytes = new byte[numBytes];

            for (int x = 0; x < numBytes; ++x)
            {
                bytes[x] = Convert.ToByte(strInput.Substring(x * 2, 2), 16);
            }

            return bytes;
        } 

        public bool IsReusable
        {
            get
            {
                return false;
            }
        }
    }
}